/////////////////////////////////////////////////////////////////////////////
// This file is part of the "Java-DAP" project, a Java implementation
// of the OPeNDAP Data Access Protocol.
//
// Copyright (c) 2007 OPeNDAP, Inc.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
/////////////////////////////////////////////////////////////////////////////
using System;
namespace NDODS.DAP
{
	
	/// <summary> This class is a convenient place to store the major and minor
	/// version number of the remote server, as well as the full version string.
	/// It is used so that classes which implement ClientIO don't need any knowledge
	/// of the DDS class.
	/// 
	/// </summary>
	/// <author>  jehamby
	/// </author>
	/// <version>  $Revision: 15901 $
	/// </version>
	/// <seealso cref="ClientIO">
	/// </seealso>
	/// <seealso cref="DDS">
	/// </seealso>
	[Serializable]
	public class ServerVersion
	{
		/// <summary> Returns the major version number.
		/// 
		/// </summary>
		/// <returns> the major version number.
		/// </returns>
		virtual public int Major
		{
			get
			{
				return major;
			}
			
		}
		/// <summary> Returns the minor version number.
		/// 
		/// </summary>
		/// <returns> the minor version number.
		/// </returns>
		virtual public int Minor
		{
			get
			{
				return minor;
			}
			
		}
		/// <summary> Returns the OPeNDAP core version as a <code>String</code>.
		/// This was a convenient place to put this information, rather than
		/// creating a new class.
		/// 
		/// </summary>
		/// <returns> the current OPeNDAP version.
		/// </returns>
		public static System.String CurrentVersion
		{
			get
			{
				return "DODS/2.18";
			}
			
		}
		
		internal const long serialVersionUID = 1;
		
		/// <summary> Major version number.</summary>
		private int major;
		/// <summary> Minor version number.</summary>
		private int minor;
		/// <summary> Full version string.</summary>
		private System.String versionString;
		
		/// <summary> Construct a new ServerVersion, setting major and minor version based
		/// on the full version string.
		/// 
		/// </summary>
		/// <param name="ver">the full version string.
		/// </param>
		public ServerVersion(System.String ver)
		{
			
			this.versionString = ver;
			this.major = this.minor = 0; // set version to default values
			// Search for the String, e.g. DODS/2.15, and set major and minor
			// accordingly
			int verIndex = ver.IndexOf("/");
			if (verIndex != - 1)
			{
				verIndex += 1; // skip over "/" to number
				//UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
				int dotIndex = ver.IndexOf('.', verIndex);
				if (dotIndex != - 1)
				{
					System.String majorString = ver.Substring(verIndex, (dotIndex) - (verIndex));
					major = System.Int32.Parse(majorString);
					System.String minorString = ver.Substring(dotIndex + 1);
					int minorDotIndex = minorString.IndexOf('.');
					if (minorDotIndex != - 1)
						minor = System.Int32.Parse(minorString.Substring(0, (minorDotIndex) - (0)));
					else
						minor = System.Int32.Parse(minorString);
				}
			}
		}
		
		/// <summary> Construct a new ServerVersion, setting major and minor version explicitly.
		/// 
		/// </summary>
		/// <param name="major">the major version number.
		/// </param>
		/// <param name="minor">the minor version number.
		/// </param>
		public ServerVersion(int major, int minor)
		{
			this.versionString = "DODS/" + major + "." + minor;
			this.major = major;
			this.minor = minor;
		}
		
		/// <summary> Returns the full version string.
		/// 
		/// </summary>
		/// <returns> the full version string.
		/// </returns>
		public override System.String ToString()
		{
			return versionString;
		}
	}
}